package com.bwsoft.portal.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Service;

import com.bwsoft.admin.domain.Account;
import com.bwsoft.admin.domain.AccountAccess;
import com.bwsoft.portal.service.AccountAccessService;
@Service(AccountAccessService.NAME)
public class AccountAccessServiceImpl extends PortalBaseServiceImpl implements AccountAccessService{
	private static Logger LOG = Logger.getLogger(AccountAccessServiceImpl.class);

	@Override
	public boolean getAccess() {
		request = ServletActionContext.getRequest();
		session = request.getSession();
		Account account = (Account)session.getAttribute("Account");
		if (account != null) {
			return accountAccessDao.findByHql("from AccountAccess a where a.account.accountId=? and a.delflag=0 and a.status=1", 
					account.getAccountId()).size() > 0;
		}
		return false;
	}

	@Override
	public AccountAccess find(Account uploader) {
		List<AccountAccess> accessList = accountAccessDao.findByHql("from AccountAccess a where a.account.accountId=?", uploader.getAccountId());
		if (accessList.size() == 0)
			return null;
		return accessList.get(0);
	}

}
